#ifndef YOUDAOSERVICE_H
#define YOUDAOSERVICE_H

#include "../WingTool/plugin/iwingtoolplg.h"
#include "settingdialog.h"
#include "transdialog.h"
#include <QDomDocument>
#include <QObject>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>

class YoudaoService : public QObject {
  Q_OBJECT
public:
  YoudaoService(QObject *parent = nullptr);
  virtual ~YoudaoService();

  bool enabled() const;

  bool cp() const;
  bool sel() const;

  // 用于本地化
  void translation() {
    tr("translate");
    tr("toggle");
    tr("setEnabled");
  }

public slots:
  // 如下含有 UI 交互
  PLUGINSRV void translate(QString word);
  PLUGINSRV void toggle();
  PLUGINSRV void setEnabled(bool enabled);

  void parse(QByteArray &content);
  QString parseCustomTrans(QDomElement &ele);
  QString parseYoudaoTrans(QDomElement &ele);

  bool isVaildWord(QString &word);
  void showSettings();
  void loadSettings();
  void saveSettings();

private:
  bool m_enabled;
  bool m_cp, m_sel;
  QNetworkAccessManager *net;
  SettingDialog *sm;
  TransDialog *dialog;
};

#endif // YOUDAOSERVICE_H
